<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2017 河源市卓锐科技有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------
// | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------

	namespace app\payment\validate;

	use app\member\model\MemberModel;
	use think\Validate;

	/**
	 * 广告验证器
	 * @package app\wechat\validate
	 * @author 蔡伟明 <314013107@qq.com>
	 */
	class Wallet extends Validate
	{
		// 定义验证规则
		protected $rule = [
			'member_id'            => 'require',
			'phone|手机号'            => 'require|number|regex:^1\d{10}',
			'validate_code|验证码'    => 'require|number|length:6,6',
			'pay_password|密码'      => 'require|number|length:6,6',
			're_pay_password|确认密码' => 'require|confirm:pay_password',
		];

		// 定义验证提示
		protected $message = [
			'pay_password.require' => '密码不能为空',
			'pay_password.length'  => '密码长度为6位数字',

			're_pay_password.require' => '确认密码不能为空',
			're_pay_password.confirm' => '两次密码不一致',

			'validate_code.require' => '验证码不能为空',
			'validate_code.number'  => '验证码必须为6位数数字',
			'validate_code.length'  => '请输入6位数验证码',
		];

		// 定义验证场景
		protected $scene = [
			'get_code'         => ['phone' => 'require|number|regex:^1\d{10}|checkPhone', 'member_id'],
			'set_pay_password' => ['phone', 'validate_code', 'pay_password', 're_pay_password'],
		];

		protected function checkPhone($rule, $value, $data)
		{
			return MemberModel::checkSelfPhone($data['phone'], $data['member_id']);
		}

	}
